package com.handpay.framework.swiper;

import java.util.concurrent.TimeUnit;

import android.content.Context;
import android.graphics.Bitmap;

import com.newland.mtype.Device;
import com.newland.mtype.ModuleType;
import com.newland.mtype.module.common.printer.Printer;
import com.newland.mtype.module.common.printer.PrinterStatus;


/**
 * 新大陆刷卡器的封装
 * 
 * @author jmshuai
 * 
 */
class NewlandSwiperME31 extends NewlandSwiperBT {

    public NewlandSwiperME31(Context context, String address) {
        super(context, address);
    }
	@Override
	public boolean printBitMap(int position, Bitmap bitmap) {
        if (null == mDeviceManager) {
            return false;
        }
        Device device = mDeviceManager.getDevice();
        if (null == device) {
            return false;
        }
        Printer printer = (Printer) device.getStandardModule(ModuleType.COMMON_PRINTER);
        if (null == printer) {
            return false;
        }
        if (PrinterStatus.NORMAL == printer.getStatus()) {
            printer.init();
            //printer.print(position, bitmap, 30, TimeUnit.SECONDS);
            //这个方法可以把图片打印在中间
            printer.print(bitmap, 30, TimeUnit.SECONDS);
            return true;
        } else {
            return false;
        }
	}

	@Override
	public boolean printString(String data) {
        if (null == mDeviceManager) {
            return false;
        }
        Device device = mDeviceManager.getDevice();
        if (null == device) {
            return false;
        }
        Printer printer = (Printer) device.getStandardModule(ModuleType.COMMON_PRINTER);
        if (null == printer) {
            return false;
        }
        if (PrinterStatus.NORMAL == printer.getStatus()) {
            printer.init();
            //printer.print(position, bitmap, 30, TimeUnit.SECONDS);
            //这个方法可以把图片打印在中间
            printer.print(data, 30, TimeUnit.SECONDS);
            return true;
        } else {
            return false;
        }
	}
    @Override
    public SwiperModel getSwiperModel() {
        return SwiperModel.ME31_BLUETOOTH;
    }
}
